/**
 * 
 * User interface - main menu
 * The entry-point for the application:
 * Create an instance of class MainMenuUI and the constructor starts the application
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * (FEN): 2006.02.24: Comments translated into English
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 *                    
 * (KBH): 2008.10.24: Change af manimenuStart to if
 */

package TUILayer;
import java.util.Scanner;
import ControlLayer.*;

public class MainMenuUI
{
   private AddressBookUI adrUI;
   private DvdUI dvdUI;
   private LendUI lendUI;
   
   /**
     * Constructor for objects of class MainMenuUI
     */
   public MainMenuUI()
   { }
   
   /**
     * Menu Section
     * 
     * mainMenuStart(), is a selection method for the user menu and executes the menu.
     * writeMainMenu(), is a visual interpretation of the user menu for the main selection section.
     * startAddressBook(), executes the addressbook menu.
     * startDvd(), executes the dvd menu.
     * startLoan(), executes the loan menu.
     * writeEnd(), printing farewell message to user opon exit.
     */
   public void mainMenuStart()
   {
       boolean exit=false;
       while (!exit)
       {
           int choise = writeMainMenu();
           if(choise == 1)
           {
               startAddressBook();
           }
           else {
               if(choise == 2) 
               {
                   startDvd();
               }
               else 
               {
                   if(choise == 3)
                   {
                       startLoan();
                   }
                   else 
                   {
                       writeEnd();
                       exit = true;
                   }
               }
           }
       }
   }
    
   private int writeMainMenu()
   {
       Scanner keyboard = new Scanner(System.in);
       System.out.println("\f *** MainMenu ***");
       System.out.println(" (1) AddressBook");
       System.out.println(" (2) DVDs");
       System.out.println(" (3) Loan");
       System.out.println(" (4) Close");
       System.out.print("\n Make your choise: ");
            
       int choise = keyboard.nextInt();
       return choise;
    }
    
    private void startAddressBook()
    {
        adrUI= new AddressBookUI();
        adrUI.start();
    }

    private void startDvd()
    {
        dvdUI= new DvdUI();
        dvdUI.start();
    }
    
    private void startLoan()
    {
        lendUI = new LendUI();
        lendUI.start();
    }
    
    private void writeEnd()
    {
        System.out.println(" ** The System is shuting down **");
    }
 }